import axios from 'axios'
// import { getStorage } from '@/utils/storage'
import store from '@/store'
import JSONbig from 'json-bigint'

// var json = '{ "value" : 9223372036854775807, "v2": 123 }'
// console.log(JSON.parse(json))
// console.log(JSONbig.parse(json).value + '')
const request = axios.create({
  baseURL: 'http://toutiao-app.itheima.net',
  transformResponse: [function (data) {
    // 对 data 进行任意转换处理
    try {
      return JSONbig.parse(data)
    } catch (error) {
      return data
    }
  }],
  timeout: 900
})
request.interceptors.request.use(config => {
  if (store.state.user) {
    config.headers.Authorization = 'Bearer ' + store.state.user.token
  }
  return config
})
request.interceptors.response.use(res => {
  return res.data.data
})
export default request
